package dotdashdot.bradz.trendsettr;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.androidplot.xy.XYPlot;
import com.androidplot.xy.XYSeries;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.ImageView;
import android.widget.SimpleAdapter;
import android.widget.TextView;

public class ClassTrendsettrAdapterAlt extends SimpleAdapter implements Filterable{

	int resource;
	Context context;
	ClassFonts fonts;
	List<? extends HashMap<String, ?>> data;
	String[] from;
	int[] to;
	boolean filter_opinions;
	final Object mLock = new Object();
	ArrayList<HashMap<String, String>> mItems;
	private ClassUberLogger logger;
	
	public ClassTrendsettrAdapterAlt(Context context,
			List<? extends HashMap<String, ?>> data, int resource, String[] from,
			int[] to, ClassFonts fonts, ClassFilterPopup info_popup) {
		super(context, data, resource, from, to);
		this.resource = resource;
		this.context = context;
		this.fonts = fonts; 
		this.data = data;
		this.from = from;
		this.to = to;
		filter_opinions = false;
		logger = new ClassUberLogger("ClassTrendsettrAdapterAlt");
		// TODO Auto-generated constructor stub
	}

	@Override
    public View getView(int position, View v, ViewGroup parent)
    {
	    View mView = super.getView(position, v, parent);
	
	    Map<String, ?> map = (HashMap<String,?>) getItem(position);
	    
	    View details = (View) mView.findViewById(R.id.text_holder);
	    
	    logger.info("Formatting listview columns");
	    
	    if(filter_opinions){
			if(Integer.valueOf(String.valueOf(map.get("Voted")))==1){
				details.setBackgroundColor(context.getResources().getColor(R.color.list_green));
			}else{
				details.setBackgroundColor(context.getResources().getColor(R.color.list_red));
			}
		}else{
			details.setBackgroundColor(context.getResources().getColor(R.color.list_white));
		}
	    TextView column;
	    int count = 0;
	        //for(int i = 0; i < map.entrySet().size();i++){
	    for (int i = 0; i < to.length; i++) {
	    	column = (TextView) mView.findViewById(to[count]);
	    	if(column != null){
	    		logger.info("Value: " + map.get(from[i]));
	        	column.setText(String.valueOf(map.get(from[i])));
	        	column.setTypeface(fonts.get_font("bold"));
	        }else{
	        	logger.info("Column null!!!");
	        }
	        count++;
	    }
	return mView;
    }
	
	public void filter_opinions(boolean filter_opinions){
		this.filter_opinions = filter_opinions;
		logger.info("FilterOpinions: " + this.filter_opinions);
	}
}
